package Triangulation;

import static org.junit.Assert.assertEquals;

import java.util.*;

import junit.framework.JUnit4TestAdapter;

import org.junit.Before;
import org.junit.Test;

import Triangulation.minimalityMetrics.ShortestEdgesMetric;
import datatypes.Edge;
import datatypes.Vertex;

public class FastLMTTriangulator_test {

	Vertex[] vertices;
	FastLMTTriangulator triangulator;
	
	public static junit.framework.Test suite() {
		return new JUnit4TestAdapter(FastLMTTriangulator_test.class);
	}
	

	
	@Before
	public void setUp() throws Exception {
		triangulator = new FastLMTTriangulator(false);
	}
	
	@Test
	public void testProcessVertices0() {
		vertices = new Vertex[5];
		vertices[0] = new Vertex(0d, 0d);
		vertices[1] = new Vertex(10d, 4d);
		vertices[2] = new Vertex(0d, 8d);
		vertices[3] = new Vertex(4d, 5d);
		vertices[4] = new Vertex(5d, 4d);
		List<Edge> LMTSkeleton = triangulator.processVertices(vertices, new ShortestEdgesMetric());
		assertEquals("LMT skeleton edge count", 8, LMTSkeleton.size());
	}

	@Test
	public void testProcessVertices1() {
		vertices = new Vertex[5];
		vertices[0] = new Vertex(0d, 0d);
		vertices[1] = new Vertex(10d, 4d);
		vertices[2] = new Vertex(0d, 8d);
		vertices[3] = new Vertex(4d, 3d);
		vertices[4] = new Vertex(5d, 4d);
		List<Edge> LMTSkeleton = triangulator.processVertices(vertices, new ShortestEdgesMetric());
		assertEquals("LMT skeleton edge count", 8, LMTSkeleton.size());
	}
	
	@Test
	public void testProcessVertices2() {
		vertices = new Vertex[6];
		vertices[0] = new Vertex(193.717277486911, 439.44630071599045);
		vertices[1] = new Vertex(662.303664921466, 439.44630071599045);
		vertices[2] = new Vertex(442.4083769633508, 771.6467780429595);
		vertices[3] = new Vertex(379.5811518324607, 622.5489260143198);
		vertices[4] = new Vertex(507.85340314136124, 619.9331742243437);
		vertices[5] = new Vertex(418.848167539267, 504.8400954653938);
		List<Edge> LMTSkeleton = triangulator.processVertices(vertices, new ShortestEdgesMetric());
		assertEquals("LMT skeleton edge count", 12, LMTSkeleton.size());
	}
	
	@Test
	public void testProcessVertices3() {
		vertices = new Vertex[6];
		vertices[0] = new Vertex(1.0, 1.0);
		vertices[1] = new Vertex(7.0, 1.0);
		vertices[2] = new Vertex(4.0, 2.0);
		vertices[3] = new Vertex(3.0, 3.0);
		vertices[4] = new Vertex(5.0, 3.0);
		vertices[5] = new Vertex(4.0, 5.0);
		List<Edge> LMTSkeleton = triangulator.processVertices(vertices, new ShortestEdgesMetric());
		assertEquals("LMT skeleton edge count", 12, LMTSkeleton.size());
	}
	
	@Test
	public void testProcessVertices4() {
		vertices = new Vertex[8];
		vertices[0] = new Vertex(0.0, 0.0);
		vertices[1] = new Vertex(4.0, 0.0);
		vertices[2] = new Vertex(4.0, 4.0);
		vertices[3] = new Vertex(0.0, 4.0);
		vertices[4] = new Vertex(1.0, 2.0);
		vertices[5] = new Vertex(2.0, 1.0);
		vertices[6] = new Vertex(3.0, 2.0);
		vertices[7] = new Vertex(2.0, 3.0);
		List<Edge> LMTSkeleton = triangulator.processVertices(vertices, new ShortestEdgesMetric());
		assertEquals("LMT skeleton edge count", 16, LMTSkeleton.size());
	}

}
